package thread;

import java.util.Scanner;

public class demo21 {
    private static volatile int flag = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            //此处搞一个循环
            while (flag == 0) {
                //啥也不做
            }
            System.out.println("t1 结束");
        });
        Thread t2 = new Thread(()->{
            //修改flag的值
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入一个flag的值");
            flag =  scanner.nextInt();
            System.out.println("t2结束");
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
    }
}
